import cloud from '@tbmp/mp-cloud-sdk';
cloud.init({
  env: 'online'
});
App({
  cloud,
  globalData:{
    userInfo:{},
    shop_id:'',
  },
  onLaunch(options) {
    let schemaData=my.getExtConfigSync&&my.getExtConfigSync()||{};
    this.globalData.shop_id=schemaData.shop_id;
    my.authorize({
      scopes: 'scope.userInfo',
      success: (res) => {
        console.log(res)
        my.getAuthUserInfo({
          success: (userInfo) => {
            console.log(userInfo)
            this.globalData.userInfo = userInfo;
            console.log(this.globalData)
            this.addUser()
          }
        })

      },
      fail:(res)=> {
        my.alert({
          title: JSON.stringify(res)
        })
      }
    })
  },
  onShow(options) {
  },
  async addUser() {
    const cloud = this.cloud;
    const res = await cloud.application.httpRequest({
      path: '/index.php/index/tb/adduser',
      method: 'POST',
      params: this.globalData.userInfo
    })
  }
});
